package top.callname.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import top.callname.bean.CourseInfoBean;
import top.callname.service.ClassService;
import top.callname.service.CourseService;
import top.callname.service.impl.ClassServiceImpl;
import top.callname.service.impl.CourseServiceImpl;

@WebServlet("/admin/course")
public class CourseServlet extends HttpServlet {

	
	private Logger logger = Logger.getLogger(CourseServlet.class);
	private CourseService courseService = new CourseServiceImpl();
	private ClassService classService = new ClassServiceImpl();
	private static final long serialVersionUID = 1L;


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String method = request.getParameter("method");
		//response.setCharacterEncoding("UTF-8");
		//PrintWriter out = response.getWriter();
		if("info".equals(method)){ 
			//根据班级查询课表
			String cid = request.getParameter("cid");
			Integer cidInt = -1;
			try {
				cidInt  = Integer.valueOf(cid);
				CourseInfoBean info = courseService.getCourseTableByCid(cidInt);
				request.setAttribute("courseInfo", info);
				request.setAttribute("classInfo", classService.getByCid(cidInt));
			} catch (Exception e) {
				logger.error("参数转换错误："+e.getMessage());
			}
			request.getRequestDispatcher("course.jsp").forward(request,response);
		}else if("info-day".equals(method)){
			//查询当天的课程
			//获取周几
			
		}
	}
	
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
